package com.bruce.starts.demo;

import com.google.common.base.Throwables;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

public class Test {
    public static void main(String[] args) {
       People people = new People("bruce",28);
       People people2 = new People();
       String name = Optional.ofNullable(people).map(p->p.getName()).orElse("默认姓名");
       String name2 = Optional.ofNullable(people2).map(p->p.getName()).orElse("默认姓名");
        System.out.println(name+"******"+name2);
    }

    public static void testThrowables(){
        try {
            throw new Exception();
        } catch (Throwable t) {
            String ss = Throwables.getStackTraceAsString(t);
            System.out.println("ss:"+ss);
            Throwables.propagate(t);
        }
    }

    private static  <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object,Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
    private static class People{
        private String name;
        private int age;
        private String address;

        public People() {
        }

        public People(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }
    }

}
